package tsing.javase.designpattern.stratege;

/**
 * @Date 28/7/2023 下午2:22
 * 实现策略的上下文
 */
public class StrategyContext {

    private Strategy strategy;

    public StrategyContext() {
    }


    /**
     * 根据不同的类型，创建策略实现类，big返回策略上下为
     * @param type
     * @return
     */
    public static  StrategyContext createStrategyContext(int type){
        Strategy strategy ;
        if(1==type){
            // 创建策略实现类1
            strategy = new BikeStrategy();
        }else if(2==type){
            // 创建策略实现类1
            strategy = new TrainStrategy();
        }else{
            // 默认策略实现类
            strategy = new BikeStrategy();
        }
        return new StrategyContext(strategy);
    }




    public StrategyContext(Strategy strategy) {
        this.strategy = strategy;
    }

    public void doTravel(){
        strategy.travel();
    }

}
